package com.tom.joke;

import androidx.appcompat.app.AppCompatActivity;

import android.os.Bundle;
import android.view.View;
import android.widget.Toast;

import com.tom.baselibrary.dialog.AlertDialog;
import com.tom.joke.view.passwordet.CustomerKeyboard;
import com.tom.joke.view.passwordet.PasswordEditText;

public class TestActivity extends AppCompatActivity implements
        PasswordEditText.PasswordFullListener,
        CustomerKeyboard.CustomerKeyboardClickListener {

    private CustomerKeyboard mCustomerKeyboard;
    private PasswordEditText mPasswordEt;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_test);

        findViewById(R.id.root).setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                clickPwd();
            }
        });
    }


    private void clickPwd() {
        AlertDialog dialog = new AlertDialog.Builder(this)
                .setContentView(R.layout.dialog_customer_keyboard)
                .fromBottom(true)
                .fullWidth()
                .create();
        dialog.show();
        mPasswordEt = dialog.getView(R.id.password_edit_text);
        mPasswordEt.setEnabled(false);
        mCustomerKeyboard = dialog.getView(R.id.custom_keyboard);
        mCustomerKeyboard.setOnCustomerKeyboardClickListener(this);
        mPasswordEt.setOnPasswordFullListener(this);
    }

    @Override
    public void click(String number) {
        mPasswordEt.addPassword(number);
    }

    @Override
    public void delete() {
        mPasswordEt.deleteLastPassword();
    }

    @Override
    public void passwordFull(String password) {
        Toast.makeText(this, "密码填充完毕：" + password, Toast.LENGTH_SHORT).show();
    }
}